package org.example.test1;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;


public abstract class Group implements Comparable<LocalDate> {

    enum Unit {
        MONTH(1, "%s年%s月"),
        QUARTER(2, "%s年%s季度"),
        HALF_YEAR(3, "%s年%s"),
        YEAR(4, "%s年");

        private final int code;
        private final String formatter;

        Unit(int code, String formatter) {
            this.code = code;
            this.formatter = formatter;
        }

        public int getCode() {
            return code;
        }

        public String getFormatter() {
            return formatter;
        }


        public static Unit find(int code){
            for(Unit unit: Unit.values()){
                if(unit.getCode()==code) return unit;
            }
            throw new IllegalArgumentException("No matching unit found for the given code: " + code);
        }
    }

    protected String displayName;
    protected LocalDate date;

    public Group() {
    }

    public Group(LocalDate date) {
        this.date = date;
        this.displayName = this.getDisplayName();
    }

    public LocalDate getDate() {
        return date;
    }//return date 用于返回成员变量的值
    public abstract String getDisplayName();

    public static Map<Group, Counter> generator(Unit unit, LocalDate start, LocalDate end) {
        Map<Group, Counter> result = new HashMap<>();
         switch (unit) {
            case MONTH :
                result=new MonthGroup().generate(start, end);break;
             case QUARTER :
                 result=new QuarterGroup().generate(start,end);break;
//             case HALF_YEAR :result;break;
//             case YEAR :break;
         };
         return result;
    }


}
